# -*- coding:utf-8 -*-

month_sun = [0,0,31,59,90,120,151,181,212,243,273,304,334,365]

def leap_year (year):
    s = -1
    if ( year % 400 == 0) or ((year % 4 == 0)and(year % 100 != 0)):
        s = 1
    else :
        s = 0
		
    return s
	
def weekx (year,month):
    week = -1
    n = (year-1900)
    N = n * 365 + (n-1)//4 
    if ((leap_year(year))and (month> 2)):
        N = N + month_sun[month] + 1
    else:
        N = N + month_sun[month]
	
    week = N%7 + 1
    return week
	
def print_calendar(year,month,firstday):
    print('*****************',year,'年',month,'月*******************') 
    print('一\t二\t三\t四\t五\t六\t日',end="")
    i = 0 
    day = 1
    month_day = month_sun[month + 1] - month_sun[month] - 1
    if ( year % 400 == 0) or ((year % 4 == 0)and(year % 100 != 0)) and month == 2:
        month_day = month_day + 1
    while  i < (firstday + month_day) + 1:
        if i >  firstday - 1 :
            print(day,end="")
            day = day + 1 
        print('\t',end="")
        if i % 7 == 0 :
            print() 
        i = i + 1

    print() 
    print('**************************************************') 
	
def main():
    year = int (input ('year  : '))
    month = int (input ('month : '))
    weekday = weekx(year,month)
    print_calendar(year,month,weekday)

if __name__ == "__main__":
    main()

	
	
